/**
 * 加载(显示)
 * @param config
 */
function showProgress (text){
	var template = document.createElement('div');
	var loadingText = text ? '<div class="text">' + text + '</div>' : '';
	var str = '<div class="container"><div class<div class="loader"></div>' + loadingText + '</div>';
	template.id = 'loading';
	template.innerHTML = str;
	document.body.appendChild(template);
}
/**
 * 加载(隐藏)
 * @param config
 */
function hideProgress (){
	var object = document.getElementById('loading');
	if(object) document.body.removeChild(object);
}
/**
 * 提示
 * @param config
 */
function showToast (text,seconds){
	if(!text) return false;
	var seconds = seconds || 1000;
	var template = document.createElement('div');
	template.id = 'toast';
	template.innerHTML = text;
	document.body.appendChild(template);
	var w = document.getElementById('toast').offsetWidth;
	w = w == 160 ? 216 : w;
	template.style.marginLeft = -w/2 + 'px';
	template.className = 'show';
	setTimeout(function (){
		document.body.removeChild(template);
	},seconds + 200);
}
/**
 * 弹窗组件
 */
function showConfirm (config,callback){
	var mask = document.createElement('div');
	mask.className = 'popup-overlay';
	var box = document.createElement('div');
	box.className = 'modal';
	var buttons = '';
	for(var i = 0;i < config.buttons.length;i ++){
		buttons += '<a href="javascript:;" class="modal-button">' + config.buttons[i] + '</a>';
	}
	box.innerHTML = '<div class="modal-inner">' +
			'<div class="modal-title">' + config.title + '</div>' + 
			'<div class="modal-text">' + config.text + '</div>' +
		'</div>' +
		'<div id="buttons-box" class="modal-buttons">' + 
			buttons +
		'</div>';
	document.body.appendChild(mask);
	document.body.appendChild(box);
	var buttonBox = document.getElementById('buttons-box');
	var btns = buttonBox.getElementsByTagName('a');
	for(var i = 0;i < btns.length;i ++){
		btns[i].onclick = function (){
			var _index = config.buttons.indexOf(this.innerHTML);
			if('function' === typeof(callback)){
				callback(_index);
			}
			mask.className = 'popup-overlay';
			box.className = 'modal';
			setTimeout(function (){
				document.body.removeChild(mask);
				document.body.removeChild(box);
			},400);
		}
	}
	setTimeout(function (){
		mask.className = 'popup-overlay modal-overlay-visible';
		box.className = 'modal modal-in';
	},100);
}
/**
 * 设置cookie
 */
function setCookie(name,value,time){
	var Days = 30;
	var exp = new Date();
	exp.setTime(exp.getTime() + time * 1000);
	document.cookie = name + "=" + escape (value) + ";expires=" + exp.toUTCString();
}
/**
 * 获取cookie
 */
function getCookie(name){
	var arr,reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
	if(arr = document.cookie.match(reg)){
		return unescape(arr[2]);
	}else{
		return null;
	}
}
/**
 * 删除获取cookie
 */
function deleteCookie(name){
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var cval = getCookie(name);
	if(cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}